// pages/2411Ayiliao-pages/appointment/trace.js
Page({
	data: {
		logs: []
	},

	addLog(url, status) {
		const time = new Date().toLocaleTimeString()
		const logs = this.data.logs
		
		// 将中文状态映射到英文类名
		let statusClass = 'default'
		if (status.includes('成功')) {
			statusClass = 'success'
		} else if (status.includes('失败')) {
			statusClass = 'failed'
		} else if (status.includes('开始测试')) {
			statusClass = 'testing'
		}
		
		logs.unshift({
			time,
			url,
			status,
			statusClass
		})
		this.setData({
			logs: logs
		})
	},

	async testAppointmentList() {
		this.addLog('http://localhost:8081/appointment/list', '开始测试')
		try {
			const result = await wx.request({
				url: 'http://localhost:8081/appointment/list',
				method: 'GET',
				timeout: 5000
			})
			this.addLog('http://localhost:8081/appointment/list', `成功 (${result.statusCode})`)
		} catch (error) {
			this.addLog('http://localhost:8081/appointment/list', `失败: ${error.errMsg}`)
		}
	},

	async testPatientList() {
		this.addLog('http://localhost:8080/patient/list', '开始测试')
		try {
			const result = await wx.request({
				url: 'http://localhost:8080/patient/list',
				method: 'GET',
				timeout: 5000
			})
			this.addLog('http://localhost:8080/patient/list', `成功 (${result.statusCode})`)
		} catch (error) {
			this.addLog('http://localhost:8080/patient/list', `失败: ${error.errMsg}`)
		}
	},

	clearLogs() {
		this.setData({
			logs: []
		})
	}
}) 